﻿using Microsoft.Practices.Composite.Events;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Matchingo.Models.SettingsProvider;

namespace GameLogicTestFixtureApp
{
    [TestClass]
    public class SettingsProviderFixture
    {
        private IEventAggregator EventAggregator { get; set; }

        [TestInitialize]
        public void Setup()
        {
            EventAggregator = new EventAggregator();
        }

        [TestMethod]
        public void ShouldLoadSettings()
        {
            GameSettingsProvider prov = new GameSettingsProvider(EventAggregator);
            // TODO:: assert that LoadSettings() was called during the initialzie
            prov.Initialize();
        }

        [TestMethod]
        public void ShouldSaveSettings()
        {
            GameSettingsProvider prov = new GameSettingsProvider(EventAggregator);
            prov.SaveSettings();
        }

        [TestMethod]
        public void ShouldLoadWhatIsSaved()
        {
            // first set of test data to save/load with
            GameSettingsProvider prov = new GameSettingsProvider(EventAggregator);
            prov.GameSettings.AIGame = false;
            prov.GameSettings.CardCount = 10;
            prov.GameSettings.PlayerName = "TestUser";

            prov.SaveSettings();

            prov = new GameSettingsProvider(EventAggregator);
            prov.Initialize();

            Assert.IsTrue(prov.GameSettings.AIGame == false);
            Assert.IsTrue(prov.GameSettings.CardCount == 10);
            Assert.IsTrue(prov.GameSettings.PlayerName == "TestUser");

            // second set of test data to save/load with
            prov = new GameSettingsProvider(EventAggregator);
            prov.GameSettings.AIGame = true;
            prov.GameSettings.CardCount = 16;
            prov.GameSettings.PlayerName = "AnotherUser";

            prov.SaveSettings();

            prov = new GameSettingsProvider(EventAggregator);
            prov.Initialize();

            Assert.IsTrue(prov.GameSettings.AIGame);
            Assert.IsTrue(prov.GameSettings.CardCount == 16);
            Assert.IsTrue(prov.GameSettings.PlayerName == "AnotherUser");
        }
    }
}
